/**
 * Created with IntelliJ IDEA.
 * User: liulinhui
 * Date: 18-10-9
 * Time: 上午11:53
 * Description: convert.js
 */
let Buffer = require('buffer/').Buffer;

function bufferToHex(buffer) {
  return global.naclInstance.to_hex(buffer);
}

function hexToBuffer(hex) {
  return global.naclInstance.from_hex(hex);
}

function useFirstEightBufferEntriesReversed(publicKeyBytes) {
  let publicKeyTransform = Buffer.alloc(8);

  for (let i = 0; i < 8; i++) {
    publicKeyTransform[i] = publicKeyBytes[7 - i];
  }

  return publicKeyTransform;
}

export default {
  bufferToHex: bufferToHex,
  hexToBuffer: hexToBuffer,
  useFirstEightBufferEntriesReversed: useFirstEightBufferEntriesReversed
};
